package cn.csust.net2.manager.server.service.impl;


import java.math.BigInteger;
import java.util.Set;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.csust.net2.manager.shared.exception.BeyondAuthorityException;
import cn.csust.net2.manager.shared.po.ResearchResult;
import cn.csust.net2.manager.shared.service.ResearchService;
import cn.csust.net2.manager.shared.util.ServiceConstant;

import com.extjs.gxt.ui.client.data.PagingLoadConfig;

@Service(value = ServiceConstant.SERVICE_NAME_RESEARCH)

public class ResearchServiceImpl extends ResearchCommanServiceImpl implements ResearchService{

	@Transactional
	@Override
	public void saveResearchResultsByPaging(PagingLoadConfig config)throws BeyondAuthorityException {
		Set<ResearchResult> resultSet = config.get(RESERACH_RESULT_SET);
		if(resultSet!=null){
			for(ResearchResult rr : resultSet){
				getResearchResultDAO().save(rr);
			}
		}
		
	}

	@Override
	public boolean canResearchByPaging(PagingLoadConfig config)throws BeyondAuthorityException {
		Long researchID = config.get(RESEARCHID);
		BigInteger studentNumber = config.get(STUDENT_NUMBER);
		if(researchID!=null&&studentNumber!=null){
			String sql = "SELECT * FROM `manager`.`student_research` WHERE  researchID = "+ RESEARCHID +" AND studentNumber = "+studentNumber;
			long count = getResearchDAO().countsBySQL(sql);
			if(count>0){
				return true;
			}
		}
		return false;
	}

}
